﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using FimetContoDeposito.BLL.Facades;
using FimetContoDeposito.BLL.Objects;
using FimetContoDeposito.DAL;
using GrayParrot.Core;
using Microsoft.Reporting.WebForms;

namespace FimetContoDeposito.OperationReports
{
    public partial class ReportAnagraficaArticoli : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                ReportViewer1.AsyncRendering = false;
                ReportViewer1.SizeToReportContent = true;
                ReportViewer1.ZoomMode = ZoomMode.FullPage;

                string m_idMagazzino = Request.QueryString["id"];

                Guid m_id = Guid.Parse(m_idMagazzino);
                ReportDataSource datasource = null;

                ReportViewer1.ProcessingMode = ProcessingMode.Local;
                ReportViewer1.LocalReport.ReportPath = Server.MapPath("../Reports/ReportAnagraficaArticoli.rdlc");

                using (CustomersFacade m_mgf = CustomersFacade.Create())
                {
                    ReturnValue<FCD_Customer> m_custRes =  m_mgf.Get(m_id);
                    if (m_custRes.HasValue && m_custRes.Value != null)
                    {
                        string m_mag = m_custRes.Value.RagioneSociale;

                        ReportParameter p1 = new ReportParameter("Nome_Magazzino", m_mag);
                        ReportViewer1.LocalReport.SetParameters(p1);
                    }
                } 

                using (AnagraficaArticoliFacade m_dc = AnagraficaArticoliFacade.Create())
                {
                    List<ArticoloBag> m_objs = m_dc.GetAllArticoliBagReport(m_id);

                    datasource = new ReportDataSource("dsAnagraficaArticoli", m_objs);

                    if (datasource != null)
                    {
                        ReportViewer1.LocalReport.DataSources.Clear();
                        ReportViewer1.LocalReport.DataSources.Add(datasource);
                    }
                }

            }
        }
    }
}